package com.keepsport.keepsportapi.controller;

import com.keepsport.keepsportapi.config.SystemConfig;
import com.keepsport.keepsportapi.dto.UserAddDto;
import com.keepsport.keepsportapi.dto.UserFindDto;
import com.keepsport.keepsportapi.dto.UserLoginDto;
import com.keepsport.keepsportapi.service.intf.UserService;

import com.keepsport.keepsportapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 　　　　　   　▍ ★∴
 * 　　　．．．．▍▍．..．█▍ ☆ ★∵ ..../
 * 　　 　◥█▅▅██▅▅██▅▅▅▅▅▅▅▅▅███◤
 * 　　 　．◥███████████████◤
 * 　 ～～～～◥█████████████◤～～～～
 *
 * @author dyb
 * @create 2022-06-29 17:13
 */
@RestController
@RequestMapping("/api/user/")
@Api(tags ="登录注册模块接口")
@CrossOrigin
public class UserController {
    @Resource
    private UserService service;
    @GetMapping("checkphone.do")
    @ApiOperation("验证手机号")
    public R check(String phone){
        return service.checkPhone(phone);
    }
    @PostMapping("loginname.do")
    @ApiOperation("账号密码登录")
    public R loginName(@RequestBody UserLoginDto dto){
        return service.loginByName(dto);
    }
    @PostMapping("logincode.do")
    @ApiOperation("验证手机号")
    public R loginCode(@RequestBody UserLoginDto dto){
        return service.loginByPhone(dto);
    }
    @PostMapping("findpass.do")
    @ApiOperation("找回密码")
    public R find(@RequestBody UserFindDto dto){
        return service.findPass(dto);
    }

    @GetMapping("loginout")
    @ApiOperation("退出登录")
    public R liginOut(HttpServletRequest request){
        //传递token 采取请求消息头
        return service.loginOut(request.getIntHeader(SystemConfig.TOKEN_HEADER));
    }
    @GetMapping("checkName.do")
    @ApiOperation("验证用户名是否存在")

    public R checkName(String name){
        return service.checkName(name);
    }

    @PostMapping(value = "save.do")
    @ApiOperation("注册账号")
    public R upload(@RequestBody UserAddDto dto){

        return service.save(dto);
    }
    @GetMapping("outByname.do")
    @ApiOperation("name 退出")
    public R outByname(String name){
        //传递token 采取请求消息头
        return service.outByname(name);
    }
}

